Skip to content

feat(DiffViewer): one collapsible prop configures the file disclosure, as on Banner - #13699

Merged
ernestt merged 1 commit into
mainfrom
feat/diffviewer-collapsible
Nov 30, 2026
Merged

ernestt merged 1 commit into
mainfrom
feat/diffviewer-collapsible

Conversation

@ernestt

@ernestt ernestt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Primary intent

DiffViewer's file disclosure takes the system's one API for a disclosure before DiffViewer moves to Core: one named feature prop, collapsible?: boolean | CollapsibleConfig, shaped like Core Banner's collapsible, in place of four DiffViewer-only props. No behavior or visual change. This is not a bug fix, a new capability, a documentation correction, or a record, so other.md fits: it changes the shape of a Lab API and keeps what it does.

User or maintainer impact

  • Builders configure DiffViewer's disclosure the way they configure Banner's and Collapsible's: one prop that takes the shared CollapsibleConfig (defaultIsOpen, isOpen, onOpenChange).
  • Lab callers of isCollapsible, isCollapsed, defaultIsCollapsed, or onCollapsedChange change their call. Lab is canary-only and promises no stability; the two callsites in this repository, a story and the DiffViewer perf sandbox page, move here.
  • Readers see no change. The default is still collapsible and open, and the toggle, its aria-expanded and aria-controls, and the collapsed render are the same.

Problem and solution fit

  1. Why it occurs: DiffViewer has its own collapse vocabulary, in collapsed polarity, while Core already has one shared disclosure config, in open polarity.
  2. Why it harms: a builder learns a second shape for the same job, and DiffViewer would take that second shape into Core.
  3. Why it matters: in Core the API becomes a stable public promise, so the shape is cheapest to settle while the component is still in Lab.
  • Primary: DiffViewerProps replaces the four props with collapsible?: boolean | CollapsibleConfig (default true), and the shared useCollapsible hook holds the open state.
  • Supporting: the doc's prop table and best practice, the tests, the ViewedToggle story, and the DiffViewer perf sandbox page move to the new prop.
// Before
<DiffViewer file={file} isCollapsible={false} />
<DiffViewer file={file} defaultIsCollapsed />
<DiffViewer file={file} isCollapsed={isCollapsed} onCollapsedChange={setIsCollapsed} />

// After
<DiffViewer file={file} collapsible={false} />
<DiffViewer file={file} collapsible={{defaultIsOpen: false}} />
<DiffViewer file={file} collapsible={{isOpen, onOpenChange: setIsOpen}} />

Defaults and compatibility: omitted or true is collapsible and starts open, as before. The polarity is open, as on Banner, so a controlled caller keeps isOpen, the negation of the old isCollapsed. Uncontrolled, onOpenChange fires beside the internal update, as onCollapsedChange did. The caller makes no new decision.

Authority

  • architecture:public-component-api INV19: a costly feature plugs in or takes a named feature prop, and "named props for features are also fine (like collapsible)".
  • The same record's INV21: one API per job. CollapsibleConfig is the existing API for a disclosure's state, and Banner's collapsible?: boolean | CollapsibleConfig (packages/core/src/Banner/Banner.tsx) is the shape this follows. DiffViewer keeps the hook's default, open, because it starts open today; Banner overrides it to start closed.
  • The change is in Lab, which is not a stable public promise; Lab members are outside the public API delta (INV24). No behavior change.

Change and evidence

  • DiffViewer.test.tsx: uncontrolled toggling reports through onOpenChange; {defaultIsOpen: false} starts collapsed and opens from the header (new case); a controlled {isOpen: false} only reports true and stays collapsed; collapsible={false} renders the path as plain text and shows the hunks.
  • Real-browser before (main) and after (this branch) in Chromium 155, from static Storybook builds, each an element screenshot of #storybook-root. Every pair is pixel-identical (pixelmatch, threshold 0).
State Before (main) After
Default, open before after
Default, collapsed from the header before after
Viewed toggle checked (controlled) before after

Viewed toggle unchecked, also identical: before, after.

The move of DiffViewer to Core, #13700, is stacked on this pull request.

Scope

Components: DiffViewer

  • This PR has one primary intent.
  • Independently removable deltas were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run packages/lab/src/DiffViewer: 94 passed.
  • ASTRYX_STRICT_LINT=1 eslint and Prettier on the changed files: clean.
  • Typecheck: Lab and Storybook clean; the sandbox reports no DiffViewer error.
  • pnpm review:pre: 0 findings. The pre-commit pnpm check:repo, pnpm check:knowledge included: clean.
  • pnpm storybook:build, then the screenshots above.

Local runs used main at 0744c42; the branch sits on 4f4b365, whose newer commits touch none of these files.

…, as on Banner

DiffViewer's file disclosure takes one named feature prop,
`collapsible?: boolean | CollapsibleConfig`, in place of `isCollapsible`,
`isCollapsed`, `defaultIsCollapsed` and `onCollapsedChange`. The config is the
shared one Banner and Collapsible take (`defaultIsOpen`, `isOpen`,
`onOpenChange`), and the shared `useCollapsible` hook holds the state.
Omitted or `true` keeps today's default: collapsible, starting open. No
behavior or visual change.
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 24, 2026 12:16am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 24, 2026
@ernestt ernestt mentioned this pull request Nov 24, 2026
4 tasks done
@astracat-bot

astracat-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 24, 2026, 12:26 AM UTC

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 82b9c7e

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
lab/DiffViewer · Storybook 97.4 kB (+170 B) · 2.3 kB CSS (0) 2,701 (−6) — · ✓ · ✓

Package size: no published package changed; no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: the deferred build and test jobs have not run on this head yet; they run once review passes, before merge.

DiffViewer's disclosure now takes Banner's collapsible?: boolean | CollapsibleConfig through the shared useCollapsible hook, the default stays collapsible and open, and both in-repo callers move to the new prop. There are no blocking findings.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim: one collapsible prop typed like Banner's replaces the four DiffViewer disclosure props: verified (packages/lab/src/DiffViewer/DiffViewer.tsx:207, packages/core/src/Banner/Banner.tsx:192).
  • Claim: omitted or true stays collapsible and starts open: verified (DiffViewer.tsx:1311, packages/core/src/Collapsible/useCollapsible.ts:104).
  • Claim: a controlled caller passes isOpen, the negation of the old collapsed value, and uncontrolled onOpenChange fires beside the internal update: verified (useCollapsible.ts:130-136).
  • Claim: the toggle, its aria-expanded and aria-controls, and the collapsed render are unchanged: verified (DiffViewer.tsx:2068-2134).
  • Claim: no behavior or visual change: verified from the code, which derives the same collapsed state; the committed before and after frames are identical files per pair.
  • Claim: the config keys match Banner's and Collapsible's: verified (Banner takes the config as one prop; Collapsible takes the same three keys as separate props, packages/core/src/Collapsible/Collapsible.tsx:249-272).
  • Claim: Lab is canary-only and the story and the perf sandbox page are the only in-repo callers to move: verified (packages/lab/package.json; no other caller passes the removed props).
  • Claim: the cited architecture clauses say what the description quotes (named feature props such as collapsible are fine; one API per job; Lab stays out of the API delta): verified against the current record.
  • Claim: the tests cover uncontrolled toggling, defaultIsOpen: false, a controlled isOpen: false, and collapsible={false}: verified (DiffViewer.test.tsx:199, :221, :262, :274).
  • Claim: 94 DiffViewer tests pass: the head has 94 test cases in that folder; the run itself awaits CI.
  • Claim: lint and typecheck are clean: CI's lint and typecheck (Lab and Storybook) passed on this head.
  • Claim: newer base commits touch none of these files: verified.
  • File packages/lab/src/DiffViewer/DiffViewer.tsx: clear.
  • File packages/lab/src/DiffViewer/DiffViewer.test.tsx: clear.
  • File packages/lab/src/DiffViewer/DiffViewer.doc.mjs: clear.
  • File apps/storybook/stories/DiffViewer.stories.tsx: clear.
  • File apps/sandbox/src/app/(fullscreen)/pages/diffviewer-perf/page.tsx: clear.

Automated review (maintainer link)

@ernestt
ernestt merged commit 0c9df81 into main Nov 30, 2026
144 of 147 checks passed
@github-actions
github-actions Bot deleted the feat/diffviewer-collapsible branch December 1, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 82b9c7e2 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant